<?php

class AddCourse extends MY_Controller {

    public function __construct() {
        parent::__construct();
        
        if($this->session->userdata('user_type') != 1 || $this->session->userdata('user_type') == null){
            show_error("You have no permission here");
        }
    }

    function index() {
        
        $this->data['main_title'] = "Add Course";
        $course = array(
                                'id' => '',
                                'course_name' => '',
                                'course_code' => '',
                                'prices' => '',
                                'hours' => '',
                                'detail' => '',
                                'videos' => ''
        );
        $this->data['course'] = $course;
            
        $courseCode = array(
                'id'    => 'course_code',
                'name'  => 'course_code'
            );
        
        $courseName= array(
                'id'    => 'course_name',
                'name'  => 'course_name'
            );
        
        $courseHours = array(
                'id'    => 'course_hours',
                'name'  => 'course_hours'
            );
        
        $courseNumVideos = array(
                'id'    => 'course_num_videos',
                'name'  => 'course_num_videos'
            );
        
        $coursePrice = array(
                'id'    => 'course_price',
                'name'  => 'course_price'
            );
        
        $courseDetail = array(
                'id'    => 'course_detail',
                'name'  => 'course_detail'
            );
        
        $btnReset = array(
                'id'    => 'btnReset',
                'name'  => 'btnReset'
            );
        
        $back = array(
                'id'    => 'back',
                'name'  => 'back'
            );
        
        $this->data['courseCode'] = $courseCode;
        $this->data['courseName'] = $courseName;
        $this->data['courseHours'] = $courseHours;
        $this->data['courseNumVideos'] = $courseNumVideos;
        $this->data['coursePrice'] = $coursePrice;
        $this->data['courseDetail'] = $courseDetail;
        $this->data['btnReset'] = $btnReset;
        $this->data['back'] = $back;
        
        $this->data['action'] = 'add';
        $this->data['main_content'] = 'add_course';
        $this->load->view('includes/template', $this->data);
    }
    
    function Submit(){
        
        $course = array(
			'CODE' => $this->input->post('course_code'),
                        'NAME' => $this->input->post('course_name'),
			'HOURS' => $this->input->post('course_hours'),
			'VIDEOS' => $this->input->post('course_num_videos'),
			'PRICE' => $this->input->post('course_price'),
			'DETAIL' => $this->input->post('course_detail')

		);
        
        $this->load->Model("Course_Model");
        $this->Course_Model->insertCourse($course);
        
        redirect('Home');
    }
}
?>
